package com.xy.biz.rs.domain.converter;

import com.xy.biz.rs.domain.bo.RecordTemplateBO;
import com.xy.biz.rs.domain.po.RecordTemplatePO;
import com.xy.biz.rs.domain.query.RecordTemplateQuery;
import com.xy.biz.rs.domain.req.ListRecordTemplateRequest;
import com.xy.biz.rs.domain.req.SaveRecordTemplateRequest;
import com.xy.biz.rs.domain.resp.GetRecordTemplateGroupResponse;
import com.xy.biz.rs.domain.resp.GetRecordTemplateResponse;
import com.xy.tool.util.BeanUtilsEx;

import java.util.Collection;
import java.util.List;

/**
 *
 *
 * @author zsp
 * @date 2022-1-4
 */
public class RecordTemplateConverter {

	public static RecordTemplatePO toPO(RecordTemplateBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new RecordTemplatePO(), true);
	}

	public static List<RecordTemplatePO> toPO(Collection<RecordTemplateBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RecordTemplatePO(), true);
	}

	public static RecordTemplateBO fromPO(RecordTemplatePO source) {
		return BeanUtilsEx.copyProperties(source, () -> new RecordTemplateBO());
	}

	public static List<RecordTemplateBO> fromPO(Collection<RecordTemplatePO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RecordTemplateBO());
	}

	public static RecordTemplateBO toBO(SaveRecordTemplateRequest source) {
		return BeanUtilsEx.copyProperties(source, () -> new RecordTemplateBO(), true);
	}

	public static List<RecordTemplateBO> toBO(Collection<SaveRecordTemplateRequest> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RecordTemplateBO(), true);
	}

	public static GetRecordTemplateResponse toResponse(RecordTemplateBO source) {
		return BeanUtilsEx.copyProperties(source,
				() -> new GetRecordTemplateResponse(),
				(s, t) -> {
					t.setGroupList(BeanUtilsEx.copyPropertiesForNewList(s.getGroupList(), () -> new GetRecordTemplateGroupResponse()));
				});
	}

	public static List<GetRecordTemplateResponse> toResponse(Collection<RecordTemplateBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source,
				() -> new GetRecordTemplateResponse(),
				(s, t) -> {
					t.setGroupList(BeanUtilsEx.copyPropertiesForNewList(s.getGroupList(), () -> new GetRecordTemplateGroupResponse()));
				});
	}

	public static RecordTemplateQuery toQuery(ListRecordTemplateRequest source) {
		if(null == source) {
			return null;
		}
		RecordTemplateQuery target = new RecordTemplateQuery(source.getPageIndex(), source.getPageSize());
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

}
